#include "message.h"
#include <string.h>

/* Setters */
void SetUser(Message * NewMessage, User NewUser)
{
	NewMessage->user =  NewUser;
}

void SetString(Message * NewMessage, char * NewString)
{
	NewMessage->string = NewString;
}

/* Getters */
User GetUser(Message NewMessage)
{
	return NewMessage.user;
}

char * GetString(Message NewMessage)
{
	return NewMessage.string;
}


void MessageTestRegression()
{
	printf("\n\n\nTestRegression du module Message :\n\n");
	
	/* Initialisation d'un UserName, d'un ID */
	char * NewName = "Pepito";
	int NewID = 4939;
	
	/* Initialisation d'un socket */
	SOCKET NewSock = socket(AF_INET, SOCK_STREAM, 0);
	
	/* Initialisation d'un sin */
	SOCKADDR_IN NewSin;
	NewSin.sin_addr.s_addr = htonl(INADDR_ANY);
   	NewSin.sin_family = AF_INET;
   	NewSin.sin_port = htons(PORT);
   	
   	/* Initialisation d'un NewUser */
   	User NewUser;
   	NewUser.userName = NewName;
   	NewUser.id = NewID;
   	NewUser.sock = NewSock;
   	NewUser.sin = NewSin;
   	
   	/* Initialisation d'une string */
   	char * NewString = "Je suis un message";
   	
   	/* Test des Setter/Getter */
   	Message NewMessage;
   	SetUser(&NewMessage, NewUser);
   	SetString(&NewMessage, NewString);
   	
   	if (strcmp(GetUserName(GetUser(NewMessage)), GetUserName(NewUser)) == 0)
   	{
   		printf("\nSetUser et GetUser...OK !");
   	}
   	else
   	{
   		printf("\nSetUser et/ou GetUser...Erreur !");
   	}
   	
   	if (GetString(NewMessage) == NewString)
   	{
   		printf("\nSetString et GetString...OK !");
   	}
   	else
   	{
   		printf("\nSetString et/ou GetString...Erreur !");
   	}
}
